import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);

//export default router;
export function createRouter(context,store){
  var router= new Router({
    mode: context.mode || 'history',
    scrollBehavior: () => ({ y: 0 }),
    routes: [
      {
        path: '/',
        name: 'home',
        component: ()=> import('@/components/Home')
      },
      {
        path: '/hello',
        name: 'HelloWorld',
        component: ()=> import('@/components/HelloWorld')
      },{
        path:'/user',
        name:'user',
        meta: { requiresAuth: true },
        component:()=> import('@/components/User')
      },{
        path:'/login',
        name:'login',
        component:()=> import('@/components/Login')
      },{
        path:'*',
        name:'404',
        component:()=> import('@/components/Error')
      }
    ]
  })
  if(context && context.mode=="hash"){
    // router.beforeEach((to, from, next) => {
    //   console.log(to)
    //     window.scroll(0, 0);
    //     if (to.matched.some(record => record.meta.requiresAuth)) {
    //       if (!store.getters.getToken) {
    //           //iview.Message.info('请登录！');
    //           return next({
    //               path: '/login',
    //               query: { redirect: to.fullPath }
    //           })
    //       }
    //     }
    //     //iview.LoadingBar.start();
    //     next() // 确保一定要调用 next()
    // })
    router.afterEach(transition => {
    
      //iview.LoadingBar.finish();
    });
  }
  return router;
}
